/*
 * @Author: szx
 * @Date: 2021-10-25 12:31:40
 * @LastEditTime: 2021-10-25 12:41:02
 * @Description:
 * @FilePath: \leetcode\122\122.go
 */
package main

import (
	"strconv"
	"strings"
)

// func maxProfit(prices []int) int {
// 	res := 0
// 	low := prices[0]
// 	for _, p := range prices {
// 		cha := p - low
// 		if cha > 0 {
// 			res += cha
// 		}
// 		low = p
// 	}
// 	return res
// }

func maxProfit(prices []int) (ret int) {
	for i := 1; i < len(prices); i++ {
		if prices[i] > prices[i-1] {
			ret += prices[i] - prices[i-1]
		}
	}
	return
}
func generateArr(str string) []int {
	s := strings.TrimLeft(str, "[")
	s = strings.TrimRight(s, "]")
	strArr := strings.Split(s, ",")
	res := make([]int, len(strArr))
	for index, val := range strArr {
		res[index], _ = strconv.Atoi(val)
	}
	return res
}

func main() {
	println(maxProfit(generateArr("[7,6,4,3,1]")))
}
